<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="12">
          <el-form-item label="学号" prop="id">
            <el-input v-model="formData.id" @blur="Bup(formData.id)" placeholder="请输入学号" clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="formData.name" placeholder="请输入姓名" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="sex">
            <el-input v-model="formData.sex" placeholder="请输入性别" clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="系别" prop="department">
            <el-input v-model="formData.department" placeholder="请输入系别" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="诊断" prop="diagnosis">
            <el-input v-model="formData.diagnosis" placeholder="请输入诊断" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="日期选择" prop="Date">
            <el-date-picker v-model="formData.date" format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择日期" clearable>
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import qs from "qs";
import axios from "axios";

export default {
  name: "MedicalRecordsAdd",
  components: {},
  props: [],
  data() {
    return {
      formData: {
        id: undefined,
        name: undefined,
        sex: undefined,
        department: undefined,
        diagnosis: undefined,
        date: null,
      },
      rules: {
        id: [{
          required: true,
          message: '请输入学号',
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: '请输入姓名',
          trigger: 'blur'
        }],
        sex: [{
          required: true,
          message: '请输入性别',
          trigger: 'blur'
        }],
        department: [{
          required: true,
          message: '请输入系别',
          trigger: 'blur'
        }],
        diagnosis: [{
          required: true,
          message: '请输入诊断',
          trigger: 'blur'
        }],
        date: [{
          required: true,
          message: '请选择日期',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      let da = this.formData;
      alert(qs.stringify(da));
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
        axios.post('http://localhost:8080/medicalrecords/Add', qs.stringify(da))
      })
    },

    Bup(id){
      const _this = this;
      axios.get('http://localhost:8080/medicaldocuments/find', {
        params:{
          id:id
        }
      }).then(function (resp){
        _this.formData = resp.data.MedDoc[0]
      })
    },

    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}

</script>
<style>
</style>
